#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/1/1 20:02
# @Author  : lizhen
# @Site    : 
# @File    : Log.py
# @Software: PyCharm
import logging

import sys


class Log:
    def __init__(self):
        self.map = {
            'error': {'filename': 'log/error.log', 'level': logging.ERROR},
            'debug': {'filename': 'log/debug.log', 'level': logging.DEBUG},
            'fmt': '[%(asctime)s] %(levelname)s [%(funcName)s: %(filename)s, %(lineno)d] %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S',
            'filemode': 'a',
        }

    def basicConfig(self, log_level):
        # SELFMODIFIED 日志兼容中文编码
        logging.basicConfig(filename=self.map[log_level]['filename'],
                            level=self.map[log_level]['level'],
                            format=self.map['fmt'],
                            datefmt=self.map['datefmt'],
                            filemode=self.map['filemode'])

    def setLog(self, log_level, msg, *args, **kwargs):
        self.handle_map = {
            'error': logging.error,
            'debug': logging.debug,
        }
        self.handle_map[log_level](msg, *args, **kwargs)


mylog = Log()

if __name__ == '__main__':
    mylog.basicConfig('debug')
    mylog.setLog('error', 'error msg')
    mylog.setLog('debug', 'debug msg')
